﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Licenta1.Expressions;

namespace Licenta1.Statements
{
    class CollectionAddStatement : Statement
    {
        string name;
        Expression obj;

        public CollectionAddStatement(Context con, Expression name, Expression e)
            : base(con)
        {
            this.name = ((IdentifierExpression)name).Name;
            obj = e;
        }

        public override void Execute()
        {
            foreach (UserCollection uc in context.userCollections)
                if (uc.NAME == name)
                {
                    uc.Add(obj);
                    return;
                }
        }

        public string NAME
        {
            get { return name; }
        }

        public Expression OBJECT
        {
            get { return obj; }
        }
    }

    class CollectionRemoveStatement : Statement
    {
        string name;
        Expression obj;

        public CollectionRemoveStatement(Context con, Expression name, Expression e)
            : base(con)
        {
            this.name = ((IdentifierExpression)name).Name;
            obj = e;
        }

        public override void Execute()
        {
            foreach (UserCollection uc in context.userCollections)
                if (uc.NAME == name)
                {
                    uc.Remove(obj);
                    return;
                }
        }
        public string NAME
        {
            get { return name; }
        }

        public Expression OBJECT
        {
            get { return obj; }
        }
    }

    class CollectionClearStatement : Statement
    {
        string name;

        public CollectionClearStatement(Context con, Expression name)
            : base(con)
        {
            this.name = ((IdentifierExpression)name).Name;
        }

        public override void Execute()
        {
            foreach (UserCollection uc in context.userCollections)
                if (uc.NAME == name)
                {
                    uc.Clear();
                    return;
                }
        }

        public string NAME
        {
            get { return name; }
        }
    }
}